<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>JS判断设备来源</title>
  <style>
    .div {
      width: 200px;
      height: 200px;
      background-color: lightblue;
      display: table-cell;
      vertical-align: middle;
    }
    .box {
      width: 50px;
      height: 50px;
      background-color: #fff;
      margin: 0 auto;
    }
  </style>
</head>
<body>
  <div class="div">
   <div class="box"></div>
  </div>


  <script>
    function deviceType() {
      var ua = navigator.userAgent;
      console.log(ua);
      var agent = ['windows','Andriod','iPhone','SymbianOS','Windows Phone','iPad','iPod'];
      var len = agent.length;
      for (var i = 0; i < len; i++) {
        if (ua.indexOf() > 0) {
          break;
        }
      }
    }
    deviceType();
    window.addEventListener('resize', function() {
      deviceType();
    })

  </script>
  
</body>
</html>